neovim telescope 插件简要教程

您所在的位置:网站首页 tele cope neovim telescope 插件简要教程

neovim telescope 插件简要教程

2024-07-15 14:59| 来源: 网络整理| 查看: 265

1. 概述

telescope 是一款强大的 neovim 插件,可以在 neovim 中提供文件名搜索和文本内容搜索的功能,以及更多复杂的功能,具体的show case可以看这里。我安装 telescope 主要是想利用它在大型项目中的文件名搜索和文本内容搜索能力,这里记录一下安装流程和使用概要。

2. 安装

首先需要安装 neovim。具体步骤可以看这里。

注意 telescope 需要nvim 0.7.0及以后的版本,因此如果你neovim 版本本身比较低的话,需要升级。

安装 neovim 后还需要进行配置。我的 neovim 配置是复制的这个仓库,按照README来进行操作,可以快速地安装好,这里不赘述。

telescope 支持多种插件系统,我使用的 vim-plug,在~/.config/nvim/init.vim 添加下面两行:

12Plug 'nvim-lua/plenary.nvim'Plug 'nvim-telescope/telescope.nvim', { 'tag': '0.1.1' }

然后在nvim中输入:PlugInstall 来安装插件。

由于插件是在GitHub上下载的,有时候可能安装会卡住,需要多尝试几次,即多次执行:PlugInstall命令。

安装完成后,执行:Telescope find_files来验证安装是否正确。如果能弹出输入框,说明安装成功了。

这个命令用来模糊匹配当前目录下的所有文件名,对于快速切换编辑文件非常方便。

3. live_grep 功能

除了find_files命令,live_grep也是一个很有用的命令,可以快速搜索某些代码,把含搜索代码的文件打开。

这个功能需要依赖ripgrep,因此要先安装它,具体安装命令如下:

123456789101112131415# macbrew install ripgrep# debian/ubuntusudo apt-get install ripgrep# archpacman -S ripgrep# centossudo yum-config-manager --add-repo=https://copr.fedorainfracloud.org/coprs/carlwgeorge/ripgrep/repo/epel-7/carlwgeorge-ripgrep-epel-7.reposudo yum install ripgrep# windows scoop install ripgrep

安装完后在命令行输入ag -h 验证安装是否成功。

ag 安装完成后,在nvim输入:Telescope live_grep 就可以搜索你想要的代码了。

4. 快捷键

上面的两个常用功能输入都比较繁琐,有没有什么快捷键可以快速打开呢?是有的,官方GitHub给出了几行代码,加入到~/.config/nvim/init.vim的最后:

1234567891011" Find files using Telescope command-line sugar.nnoremap ff Telescope find_filesnnoremap fg Telescope live_grepnnoremap fb Telescope buffersnnoremap fh Telescope help_tags" Using Lua functionsnnoremap ff lua require('telescope.builtin').find_files()nnoremap fg lua require('telescope.builtin').live_grep()nnoremap fb lua require('telescope.builtin').buffers()nnoremap fh lua require('telescope.builtin').help_tags()

然后在Normal模式输入\ff就可以打开find_files命令窗口,输入\fg就可以打开live_grep窗口了。

更多详细命令和功能参见GitHub 页面。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3